from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from src.core.models.enums import Currency, PaymentStatus
from src.database.models.base import TimedBaseModel


class Bill(TimedBaseModel):
    __tablename__ = "bill"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    summ: Mapped[float] = mapped_column(nullable=False)
    currency: Mapped[Currency]
    invoice_id: Mapped[str] = mapped_column(String(50), nullable=True)
    status: Mapped[PaymentStatus] = mapped_column(server_default="waiting_payment")
    user = relationship("User", back_populates="bills")
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))

    def __repr__(self):
        return f"<Счет №{self.id} на сумму {self.summ}$>"

    def __str__(self):
        return self.__repr__()
